/* jshint esversion: 6 */
import Vue from 'vue';

import './components.css';

let huanet = new Vue();
// 询问框
Vue.prototype.hw_confirm = function (msg,callback) {
  huanet.$msgbox({
    title: '提示',
    message:msg,
    showCancelButton: true,
    dangerouslyUseHTMLString:true,
    confirmButtonText: '确定',
    cancelButtonText: '取消',
    beforeClose: (action, instance, done) => {
      done();
    }
  }).then(action => {
    callback();
  }).catch(error => {
  });
};
// 消息提示
Vue.prototype.hw_message = function (msg) {
  huanet.$message({
    message: msg,
    center:true,
    customClass:'hw_message',
    duration:2000
  });
};
// 成功提示
Vue.prototype.hw_success = function (msg) {
  huanet.$message({
    message: msg,
    type: 'success',
    center:true,
    customClass:'hw_message',
    duration:2000
  });
};
// 警告提示
Vue.prototype.hw_warn = function (msg) {
  huanet.$message({
    message: msg,
    type: 'warning',
    center:true,
    customClass:'hw_message',
    duration:2000
  });
};
// 错误提示
Vue.prototype.hw_error = function (msg) {
  huanet.$message({
    message: msg,
    type: 'error',
    center:true,
    customClass:'hw_message',
    duration:2000
  });
};
// 请求结果处理
Vue.prototype.hw_result = function(data,show,vm,callback) {
  if(data.code == 'S0000'){
    callback();
  }else if(show){
    if(data.code == 'N0001'){// 登录失败或未登录
      // vm.$router.push({name:'Login'});
    }else{
      huanet.$message({
        message: data.msg,
        type: 'error',
        center:true,
        customClass:'hw_message',
        duration:2000
      });
    }

  }

};

